local DIY = require "packages.diy_utility.diy_utility"

local skel = fk.CreateSkill {
  name = "rmt__yizhu",
  tags = {DIY.ReadySkill},
}

skel:addEffect("active", {
  mute = true,
  card_num = 0,
  target_num = 1,
  prompt = function (self, player, selected_cards, selected_targets)
    return "#rmt__yizhu"..DIY.getSwitchState(player, skel.name)
  end,
  can_use = function(self, player)
    return true
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, player, to_select, selected, selected_cards)
    if #selected == 0 then
      if DIY.getSwitchState(player, skel.name) == 1 then
        return not to_select.chained
      else
        return true
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:notifySkillInvoked(player, skel.name, "control")
    local n = DIY.getSwitchState(player, skel.name)
    DIY.changeSwitchState(player, skel.name)
    if n == 1 then
      player:broadcastSkillInvoke(skel.name, table.random({1, 2}))
      room:addTableMark(player, skel.name, target.id)
      target:setChainState(true)
    elseif n == 2 then
      player:broadcastSkillInvoke(skel.name, table.random({3, 4}))
      target:turnOver()
    elseif n == 3 then
      player:broadcastSkillInvoke(skel.name, table.random({5, 6}))
      room:killPlayer{who = target, killer = player}
    end
  end,
})

skel:addEffect(fk.ChainStateChanged, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name, true) and not target.chained and table.contains(player:getTableMark("rmt__yizhu"), target.id)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, "rmt__yizhu", "special")
    player:broadcastSkillInvoke("rmt__yizhu", table.random({7, 8}))
    DIY.setSwitchState(player, skel.name, 1, 3)
    room:removeTableMark(player, "@diy_skill_readying", skel.name)
    room.logic:trigger(DIY.SkillReadyFinish, player, {
      who = player, skill = skel.name, reason = skel.name
    })
  end,
})

skel:addAcquireEffect(function (self, player, is_start)
  DIY.setSwitchState(player, self.name, 1, 3)
end)

skel:addLoseEffect(function (self, player, is_death)
  DIY.removeSwitchSkill(player, self.name)
end)

Fk:loadTranslationTable{
  ["rmt__yizhu"] = "抑诛",
  [":rmt__yizhu"] = "转换技，<a href='diy_ready_skill'>蓄势技</a>，出牌阶段，你可以令一名角色①横置②翻面③死亡。"..
  "当你发动①选择的角色武将牌重置后，重置此技能的转换技选项和蓄势技状态。",

  ["#rmt__yizhu1"] = "抑诛：你可以令一名角色横置！",
  ["#rmt__yizhu2"] = "抑诛：你可以令一名角色翻面！",
  ["#rmt__yizhu3"] = "抑诛：你可以杀死一名角色！",

  ["$rmt__yuling1"] = "御国之术者，政出于一。",
  ["$rmt__yuling2"] = "天命有常者，在予一人。",
  ["$rmt__yizhu1"] = "彼招摇过市，其心可知也。",
  ["$rmt__yizhu2"] = "彼跋扈至此，令孤芒刺在背。",
  ["$rmt__yizhu3"] = "庙堂甚高，无卿之禄。",
  ["$rmt__yizhu4"] = "金樽共汝饮，公自求多福吧。",
  ["$rmt__yizhu5"] = "白刃不相饶！",
  ["$rmt__yizhu6"] = "诛此獠！使乱臣贼子惧。",
  ["$rmt__yizhu7"] = "尔来非亮剑之时也。",
  ["$rmt__yizhu8"] = "诛枭立威，非之时也，且姑待之。",
}

return skel
